import 'package:cached_network_image/cached_network_image.dart';
import 'package:changxindianzishangwu/model/address_book_model.dart';
import 'package:changxindianzishangwu/pages/contacts/conversation_friend_page.dart';
import 'package:changxindianzishangwu/util/app_color.dart';
import 'package:changxindianzishangwu/util/colors.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_user_full_info.dart';

class WidGetUtils {
  static String getImgPath(String name, {String format: 'png'}) {
    return 'assets/images/$name.$format';
  }

  static void showSnackBar(BuildContext context, String msg) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(msg),
        duration: Duration(seconds: 2),
      ),
    );
  }

  static Widget getSusItem(BuildContext context, String tag,
      {double susHeight = 30}) {
    if (tag == '★') {
      tag = '★ 热门城市';
    }
    return Container(
      height: susHeight,
      width: MediaQuery.of(context).size.width,
      padding: EdgeInsets.only(left: 16.0),
      color: Color(0xFFF3F4F5),
      alignment: Alignment.centerLeft,
      child: Text(
        '$tag',
        softWrap: false,
        style: TextStyle(
          fontSize: 14.0,
          color: Color(0xFF666666),
        ),
      ),
    );
  }

  static V2TimUserFullInfo _userEntity;
  static List userIDList;
  static List<V2TimUserFullInfo> userEntity;
  static var userId;

  List<AddressBookModel> someUser = [];

  static Widget getListItem(BuildContext context, AddressBookModel model,
      V2TimUserFullInfo userEntity,
      {double susHeight = 60}) {
    //print("::tihis::${userEntity.faceUrl}");
    return Container(
      alignment: Alignment.bottomCenter,
      padding: EdgeInsets.only(left: width(15), right: width(20)),
      height: 60,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          InkWell(
            onTap: () {
              Get.off(() => ConversationFriendPage(
                    model: model,
                    type: 2,
                  ));
            },
            child: Row(
              children: [
                Container(
                    height: width(40),
                    width: width(40),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(6),
                      child: CachedNetworkImage(
                        imageUrl: model.headerUrl,
                        fit: BoxFit.cover,
                      ),
                    )),
                Expanded(
                  flex: 1,
                  child: Padding(
                    padding: const EdgeInsets.only(left: 8, right: 15),
                    child: Text(
                      model.name ?? "",
                      style: TextStyle(fontSize: sp(15)),
                    ),
                  ),
                ),

                ///在线时间
                // _onlineView()
              ],
            ),
          ),
          Divider(
            height: 1,
            indent: width(48),
          )
        ],
      ),
    );
//    return Column(
//      mainAxisSize: MainAxisSize.min,
//      children: <Widget>[
//        Offstage(
//          offstage: !(model.isShowSuspension == true),
//          child: getSusItem(context, model.getSuspensionTag(),
//              susHeight: susHeight),
//        ),
//        ListTile(
//          title: Text(model.name),
//          onTap: () {
//            LogUtil.e("onItemClick : $model");
//            Utils.showSnackBar(context, 'onItemClick : ${model.name}');
//          },
//        )
//      ],
//    );
  }

  static Column _onlineView() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.end,
      children: [
        Image.asset(
          "images/ic_gray_cir.png",
          width: width(8),
        ),
        Padding(
          padding: const EdgeInsets.only(top: 3),
          child: Text(
            "时长",
            style: TextStyle(fontSize: sp(10), color: AppColor.colorText85),
          ),
        )
      ],
    );
  }
}
